home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / amiga.free / sorgenti vari / wolf3dmacsource.sit / Wolf3DMacSource / PushWall.c < prev    next >
C/C++ Source or Header  |  1994-09-13  |  3KB  |  123 lines

  1. #include "wolfdef.h"
  2.  
  3. #define PWALLSPEED 4        /* Micropixels per 60th of a second */
  4.  
  5. pushwall_t PushWallRec;                /* Record for the single pushwall in progress */
  6.  
  7. /**********************************
  8.  
  9.     Set pwallychange and pwallxchange
  10.     Uses pwallpos,pwalldir
  11.  
  12. **********************************/
  13.  
  14. void SetPWallChange(void)
  15. {
  16.     Word pos;
  17.     
  18.     pos = PushWallRec.pwallpos&(FRACUNIT-1);    /* Get the pixel fraction */
  19.     PushWallRec.pwallxchange = 0;        /* No motion yet */
  20.     PushWallRec.pwallychange = 0;
  21.     switch (PushWallRec.pwalldir) {        /* Which way? */
  22.     case CD_NORTH:
  23.         PushWallRec.pwallychange = -pos;        /* Y motion */
  24.         return;
  25.     case CD_EAST:
  26.         PushWallRec.pwallxchange = pos;            /* X motion */
  27.         return;
  28.     case CD_SOUTH:
  29.         PushWallRec.pwallychange = pos;            /* Y motion */
  30.         return;
  31.     case CD_WEST:
  32.         PushWallRec.pwallxchange = -pos;        /* X motion */
  33.     }
  34. }
  35.  
  36. /**********************************
  37.  
  38.     Marks the dest tile as blocked and begins a push wall sequence
  39.     Uses pwallx,pwally,pwalldir
  40.  
  41. **********************************/
  42.  
  43. void PushWallOne(void)
  44. {
  45.     PushWallRec.pwallcheckx = PushWallRec.pwallx;
  46.     PushWallRec.pwallchecky = PushWallRec.pwally;
  47.  
  48.     switch (PushWallRec.pwalldir) {
  49.     case CD_NORTH:
  50.         PushWallRec.pwallchecky--;
  51.         break;
  52.     case CD_EAST:
  53.         PushWallRec.pwallcheckx++;
  54.         break;
  55.     case CD_SOUTH:
  56.         PushWallRec.pwallchecky++;
  57.         break;
  58.     case CD_WEST:
  59.         PushWallRec.pwallcheckx--;
  60.     }
  61.     tilemap[PushWallRec.pwallchecky][PushWallRec.pwallcheckx] |= TI_BLOCKMOVE | TI_BLOCKSIGHT;
  62.     StartPushWall();    /* let the refresh do some junk*/
  63. }
  64.  
  65. /**********************************
  66.  
  67.     Initiate a pushwall sequence
  68.     Call with x,y,dir of wall to push
  69.  
  70. **********************************/
  71.  
  72. void PushWall(Word x,Word y,Word dir)
  73. {
  74.     PlaySound(SND_PWALL);    /* Play the wall sound */
  75.     PushWallRec.pwallx = x;            /* Save the x,y in my globals */
  76.     PushWallRec.pwally = y;
  77.     PushWallRec.pwalldir = dir;        /* Save the wall direction */
  78.     PushWallOne();        /* Initiate the animation */
  79.     PushWallRec.pwallcount = 2;        /* Move two cells */
  80.     ++gamestate.secretcount;    /* Secret area found */
  81.     PushWallRec.pwallpos = PWALLSPEED/2;    /* Begin the move */
  82.  
  83. /* mark the segs that are being moved */
  84.  
  85.     tilemap[y][x] &= ~TI_PUSHWALL;    /* Clear the pushwall bit */
  86.     SetPWallChange();        /* Set pwallchange */
  87. }
  88.  
  89. /**********************************
  90.  
  91.     Continue any pushwall animations, called by the main loop
  92.  
  93. **********************************/
  94.  
  95. void MovePWalls (void)
  96. {
  97.     if (!PushWallRec.pwallcount) {    /* Any walls to push? */
  98.         return;            /* Nope, get out */
  99.     }
  100.  
  101.     PushWallRec.pwallpos += PWALLSPEED*TicCount;    /* Move the wall a little */
  102.     SetPWallChange();        /* Set the wall for the renderer */
  103.     if (PushWallRec.pwallpos<256) {        /* Crossed a tile yet? */
  104.         return;                /* Exit now */
  105.     }
  106.     PushWallRec.pwallpos -= 256;        /* Mark as crossed */
  107.     
  108.     /* the tile can now be walked into */
  109.     
  110.     tilemap[PushWallRec.pwally][PushWallRec.pwallx] &= ~TI_BLOCKMOVE;    /* The movable block is gone */
  111.     AdvancePushWall();        /* Remove the bsp seg */
  112.  
  113.     if (!--PushWallRec.pwallcount) {    /* Been pushed 2 blocks?*/
  114.         StopSound(SND_PWALL);    /* Play the wall sound */
  115.         PlaySound(SND_PWALL2);    /* Play the wall stop sound */
  116.         return;                /* Don't do this anymore! */
  117.     }
  118.     PushWallRec.pwallx = PushWallRec.pwallcheckx;    /* Set the tile to the next cell */
  119.     PushWallRec.pwally = PushWallRec.pwallchecky;
  120.     PushWallOne();            /* Push one more record */
  121. }
  122.  
  123.